import os
import time
import multiprocessing


def consumer(queue):
    while True:
        cnt = queue.get()
        print("I am a consumer cnt = {}, process id = {}".format(cnt, os.getpid()))
        time.sleep(1)


def producer(queue):
    cnt = 0
    while True:
        queue.put(cnt)
        print("I am a producer cnt = {}, process id = {}".format(cnt, os.getpid()))
        time.sleep(1)
        cnt += 1


if __name__ == "__main__":
    queue = multiprocessing.Queue()
    p1 = multiprocessing.Process(target=consumer, args=(queue,))
    p2 = multiprocessing.Process(target=producer, args=(queue,))
    p1.start()
    p2.start()
